/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dto;

import dao.DepartmentDAO;
import dao.EmployeeDAO;
import dao.ProjectDAO;
import java.io.Serializable;
import java.util.Date;

/**
 *
 * @author Canh
 */
public class EmployeeDiary implements Serializable {

    /**
     * [ID] [int] IDENTITY(1,1) NOT NULL, [EmployeeNumber] [int] NULL,
     * [CurrentProject] [int] NULL, [CurrentDepartment] [int] NULL,
     * [TransferProject] [int] NULL, [TransferDepartment] [int] NULL,
     * [TransferRelievingDate] [date] NULL, [TransferJoiningDate] [date] NULL,
     * [Approval] [bit] NULL, [CreateDate] [date] NULL, [Manager] [int] NULL,
     * [Reason] [text] NULL, [Information] [text] NULL,
     */
    int id, employeeNumber, currentProject, transferProject, currentDepartment, transferDepartment, manager;

    String reason, information;
    int approval;
    Date transferRelievingDate, transferJoiningDate, createDate;

    public TRANSFER_STATUS getStatus() {
        return TRANSFER_STATUS.fromInt(approval);
    }

    public void setStatus(TRANSFER_STATUS status) {
        this.approval = status.getValue();
    }

    public int getId() {
        return id;
    }

    public EmployeeDiary() {
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getEmployeeNumber() {
        return employeeNumber;
    }

    public void setEmployeeNumber(int employeeNumber) {
        this.employeeNumber = employeeNumber;
    }

    public int getCurrentProject() {
        return currentProject;
    }

    public void setCurrentProject(int currentProject) {
        this.currentProject = currentProject;
    }

    public int getTransferProject() {
        return transferProject;
    }

    public void setTransferProject(int transferProject) {
        this.transferProject = transferProject;
    }

    public int getCurrentDepartment() {
        return currentDepartment;
    }

    public void setCurrentDepartment(int currentDepartment) {
        this.currentDepartment = currentDepartment;
    }

    public int getTransferDepartment() {
        return transferDepartment;
    }

    public void setTransferDepartment(int transferDepartment) {
        this.transferDepartment = transferDepartment;
    }

    public int getManager() {
        return manager;
    }

    public void setManager(int manager) {
        this.manager = manager;
    }

    public String getReason() {
        return reason;
    }

    public void setReason(String reason) {
        this.reason = reason;
    }

    public String getInformation() {
        return information;
    }

    public void setInformation(String information) {
        this.information = information;
    }

    public int isApproval() {
        return approval;
    }

    public void setApproval(int approval) {
        this.approval = approval;
    }

    public Date getTransferRelievingDate() {
        return transferRelievingDate;
    }

    public void setTransferRelievingDate(Date transferRelievingDate) {
        this.transferRelievingDate = transferRelievingDate;
    }

    public Date getTransferJoiningDate() {
        return transferJoiningDate;
    }

    public void setTransferJoiningDate(Date transferJoiningDate) {
        this.transferJoiningDate = transferJoiningDate;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public EmployeeDiary(int id, int employeeNumber, int currentProject, int transferProject, int currentDepartment, int transferDepartment, String reason, Date createDate) {
        this.id = id;
        this.employeeNumber = employeeNumber;
        this.currentProject = currentProject;
        this.transferProject = transferProject;
        this.currentDepartment = currentDepartment;
        this.transferDepartment = transferDepartment;
        this.reason = reason;
        this.createDate = createDate;
    }

    public EmployeeDiary(int id, int employeeNumber, int currentProject, int transferProject, int currentDepartment, int transferDepartment, int manager, String reason, String information, int approval, Date transferRelievingDate, Date transferJoiningDate, Date createDate) {
        this.id = id;
        this.employeeNumber = employeeNumber;
        this.currentProject = currentProject;
        this.transferProject = transferProject;
        this.currentDepartment = currentDepartment;
        this.transferDepartment = transferDepartment;
        this.manager = manager;
        this.reason = reason;
        this.information = information;
        this.approval = approval;
        this.transferRelievingDate = transferRelievingDate;
        this.transferJoiningDate = transferJoiningDate;
        this.createDate = createDate;
    }

    public String getCurrentProjectText() {
        ProjectDAO dao = new ProjectDAO();
        Project p = dao.readByID(this.currentProject);
        if (p == null) {
            return "";
        }
        return p.getId() + ". " + p.getName();
    }

    public String getTransferProjectText() {
        ProjectDAO dao = new ProjectDAO();
        Project p = dao.readByID(this.transferProject);
        if (p == null) {
            return "";
        }
        return p.getId() + ". " + p.getName();
    }

    public String getCurrentDepartmentText() {
        DepartmentDAO dao = new DepartmentDAO();
        Department p = dao.readByID(this.currentDepartment);
        if (p == null) {
            return "";
        }
        return p.getId() + ". " + p.getName();
    }

    public String getTransferDepartmentText() {
        DepartmentDAO dao = new DepartmentDAO();
        Department p = dao.readByID(this.transferDepartment);
        if (p == null) {
            return "";
        }
        return p.getId() + ". " + p.getName();
    }

    public String getEployeeInfo() {
        EmployeeDAO dao = new EmployeeDAO();
        Employee e = dao.readById(employeeNumber);
        return e.getEmpNum() + ". " + e.getFirstName() + " " + e.getLastName();
    }

    public enum TRANSFER_STATUS {

        TRANSFER_UNVIEW(0),
        TRANSFER_VIEWED(1),
        TRANSFER_APPROVAL(2),
        TRANSFER_UNAPPROVAL(3);

        private int value;

        TRANSFER_STATUS(int newValue) {
            value = newValue;
        }

        public int getValue() {
            return value;
        }

        public static TRANSFER_STATUS fromInt(int value) {
            switch (value) {
                case 3:
                    return TRANSFER_UNAPPROVAL;

                case 2:
                    return TRANSFER_APPROVAL;
                case 1:
                    return TRANSFER_VIEWED;
                default:
                    return TRANSFER_UNVIEW;
            }
        }
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final EmployeeDiary other = (EmployeeDiary) obj;
        if (this.id != other.id) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 83 * hash + this.id;
        return hash;
    }

    @Override
    public String toString() {
        return "EmployeeDiary{" + "id=" + id + '}';
    }
}
